
#pragma once

#include <TCHAR.h>
#include "Win32.String.h"

// -----------------------------------------------------------------------------

namespace Kif
{
namespace Win32
{

class TIMESTAMP_STRUCT
{
private:
public:

   TIMESTAMP_STRUCT()
   {
      Now();
   }

   short int Year; 
   unsigned short int Month; 
   unsigned short int Day; 
   unsigned short int Hour; 
   unsigned short int Minute; 
   unsigned short int Second; 
   unsigned long int Fraction;

   void Now();

   inline void CheckDateTime()
   {
      if (Year == 0)
         Now();
      if (Hour > 23)
      {
         Hour = 0 ;
         Minute = 0 ;
         Second = 0 ;
         Fraction = 0 ;
      }
   }

}  ;

class DateTime : public TIMESTAMP_STRUCT
{
public:

   static const int MaxYmdHmsStringLength = 19;
   static const int MinYmdHmsStringLength = 14;

   static const int MaxYmdStringLength = 10;
   static const int MinYmdStringLength =  6;

   static const int MaxHmsStringLength =  8;
   static const int MinHmsStringLength =  6;

   static Kif::Win32::String *GetYmdHmsString(
      DateTime *dateTime,
      short dayLength,  TCHAR daySeparator,
      short timeLength, TCHAR timeSeparator,
      bool  separated);

   static Kif::Win32::String *GetYmdHmsString(
      short dayLength,  TCHAR daySeparator,
      short timeLength, TCHAR timeSeparator,
      bool separated)
   {
      DateTime dt;
      SYSTEMTIME dtime;
      GetLocalTime(&dtime) ;
      dt.Year     = dtime.wYear;
      dt.Month    = dtime.wMonth;
      dt.Day      = dtime.wDay;
      dt.Hour     = dtime.wHour;
      dt.Minute   = dtime.wMinute;
      dt.Second   = dtime.wSecond;
      dt.Fraction = 0;
      return(GetYmdHmsString(&dt,dayLength,daySeparator,timeLength,
         timeSeparator,separated));
   }

   inline static Kif::Win32::String *GetYmdHmsString(
      short dayLength,  TCHAR daySeparator,
      short timeLength, TCHAR timeSeparator)
   {  return(GetYmdHmsString(
          dayLength,daySeparator,timeLength,timeSeparator,true)); }

   inline static Kif::Win32::String *GetYmdHmsString()
   {
      return(GetYmdHmsString(
         MaxYmdStringLength,'-',MaxHmsStringLength,':',true));
   }

   inline static Kif::Win32::String *GetYmdHmsNameString()
   {
      return(GetYmdHmsString(
         MaxYmdStringLength,0,MaxHmsStringLength,0,false));
   }

   inline static Kif::Win32::String *GetYmdString(
      DateTime *dateTime, short length, TCHAR separator)
   {  return(GetYmdHmsString(dateTime,MaxYmdStringLength,separator,0,0,false)); }

   inline static Kif::Win32::String *GetYmdString(
      DateTime *dateTime, TCHAR separator)
   {  return(GetYmdHmsString(dateTime,MaxYmdStringLength,separator,0,0,false)); }

   inline static Kif::Win32::String *GetYmdString(short length,TCHAR separator)
   {  return(GetYmdHmsString(length,separator,0,0,false)); }

   inline static Kif::Win32::String *GetYmdString()
   {  return(GetYmdHmsString(MaxYmdStringLength,'-',0,0,false)); }

   static DateTime *CCYYMMDD_ToDate(TCHAR *string);
   static DateTime *MMDDCCYY_ToDate(TCHAR *string);
   static DateTime *DD_MMM_YYYY_ToDate(Kif::Win32::String &string);

}  ;  // end of DateTime class

class TimeSpan
{
   public:
   static double ToMilliseconds(DateTime &endTime, DateTime &startTime);
}  ;

}  // end of Kif::Win32 namespace
}  // end of Kif namespace

